package com.wm.blog_gateway.auth;

import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.net.URISyntaxException;

/***
 * @ClassName: LogoutAuthSuccessHandler
 * @Description: 登录退出  todo 登录退出
 * @Author: 半卷流年
 * @Create_time: 18:24 2020-3-30
 */
@Component
public class LogoutAuthSuccessHandler implements ServerLogoutSuccessHandler {

    @Override
    public Mono<Void> onLogoutSuccess(WebFilterExchange webFilterExchange, Authentication authentication) {
        try {
            URI url = new URI("http://localhost:9090/blog/admin/");
            webFilterExchange.getExchange().getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY);
            webFilterExchange.getExchange().getResponse().getHeaders().setLocation(url);
            return Mono.empty();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return Mono.empty();
    }
}